var ns,toast;
app = new Vue({
    el: '#app',
    data: {
        showsearch: false,
        showsearchmonth: false,
        showsearchparam: false,
        showtime:false,
        ProjectName:'',
        ReportType:0,//0 设备巡检  1 安防巡更  2 环境保洁
        form: {
            startMonth: '', 
            activeDateDesc: '月份',
            ProjectCompanyType: 1,
            ProjectID:0,
            ProjectIDs: [],
        },
        summary: {},
        projectList: [],
        list:[], 
        WBlist:[],  ////维保数据
        XJlist:[],  ////巡检数据
        userList:[],  ////员工工时
    },
    methods: {
        get_data: function () {
            var that = this;
            that.getSearchParams();
            that.doSearch();
        },
        doSelectProject: function (ID,Name) {
            var that = this;
            that.ProjectName=Name;
            that.form.ProjectID=ID;
            that.form.ProjectIDs=[];
            that.form.ProjectIDs.push(ID);
            that.showsearchparam = false;
            that.doSearch();
        },
        //筛选数据
        getSearchParams: function () {
            var that = this;
            var options = {};
            options.action = "gettaskanalysisparams";
            ns.post(options, function (succeed, data, err) {
                if (succeed) {
                    that.projectList = data.projectList;
                    // if(that.projectList!=undefined&&that.projectList.length>0){
                    //     that.doSelectProject(that.projectList[0].ID,that.projectList[0].Name); 
                    // }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },
        onShowTime:function(IsShow){
            var that=this;
            that.showtime=IsShow;
        },
        doSelectSearchParam: function (type) {
            var that = this;
            if (type == 1) { //筛选
                that.showsearchparam = !that.showsearchparam;
                that.showsearchmonth = false;
            }
            if (type == 2) { //按月
                that.showsearchparam = false;
                that.showsearchmonth = !that.showsearchmonth;
            }
            that.showsearch = that.showsearchparam || that.showsearchmonth;
            // if (type == 2 && that.showsearchmonth) {
            //     setTimeout(function () {
            //         that.initPicker();
            //     }, 100);
            // }
        },

        do_checklist:function(){
            var that=this;
            ns.openWin('quality_checklist_frm', '考核项目')
        },
        doHideSearch: function () {
            var that = this;
            that.showsearchparam = false;
            that.showsearchmonth = false;
            that.showsearch = false;
        },
        doSearch: function () {
            var that = this;
            that.doHideSearch();
            that.get_xunjianData();
        },
        get_xunjianData:function(){
            var that = this;
            that.list=[];
            var options = {};
            options.ProjectID=that.form.ProjectID;
            options.DayTime = that.form.startMonth;
            options.action = "getqualityinspectionlist";
            toast.loading({
                title: "加载中",
                duration: 2000
            }, function (ret) { });
            ns.post(options, function (succeed, data, err) {
                toast.hide();
                if(succeed){
                    if(data.status){
                        that.list=data.data;
                    }else{
                        api.toast({
                            msg: '数据错误',
                            duration: 2000,
                            location: 'bottom'
                        });
                    }

                }else{
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            });
        },


        initPicker: function () {
            var _this = this;
            (function ($, doc) {
                $.init();
                $.ready(function () {
                    //月份
                    var btn = document.querySelector('#datemonth');
                    btn.addEventListener('tap', function () {
                        var _self = this;
                        if (_self.picker) {
                            _self.picker.show(function (rs) {
                                _this.form.startMonth = rs.value;
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        } else {
                            var optionsJson = this.getAttribute('data-options') || '{}';
                            var options = JSON.parse(optionsJson);
                            var id = this.getAttribute('id');
                            _self.picker = new $.DtPicker(options);
                            _self.picker.show(function (rs) {
                                var timer = setTimeout(function () {
                                    clearTimeout(timer);
                                    _this.form.startMonth = rs.value;
                                    _this.doSearch();
                                }, 300);
                                _self.picker.dispose();
                                _self.picker = null;
                            });
                        }
                    }, false);
                });
            })(mui, document);
        },
    }
});
apiready = function () {
    api.parseTapmode();
    ns = window.Foresight.Util;
    toast = new auiToast();
    var nowDate = new Date();
    // var Y = nowDate.getFullYear();
    // var M = nowDate.getMonth() + 1 < 10 ? '0' + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
    // app.form.startMonth = Y+'-'+M;//初始化默认当前月
    app.ReportType=api.pageParam.servicetype || 0;
    app.form.ProjectID=api.pageParam.ProjectID || 0;
    app.ProjectName=api.pageParam.ProjectName;
    app.form.startMonth=api.pageParam.startMonth || 0;
    app.initPicker();
    app.get_data();

};
